package com.ruoyi.eduadmin.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.eduadmin.service.IItStudentesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eduadmin.domain.ItProblemTrackingRecord;
import com.ruoyi.eduadmin.service.IItProblemTrackingRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 跟踪记录Controller
 * 
 * @author ruoyi
 * @date 2022-12-29
 */
@RestController
@RequestMapping("/problem")
public class ItProblemTrackingRecordController extends BaseController
{
    @Autowired
    private IItProblemTrackingRecordService itProblemTrackingRecordService;

    @Autowired
    private IItStudentesService itStudentesService;

    /**
     * 查询跟踪记录列表
     */
    @RequiresPermissions("eduadmin:problem:list")
    @GetMapping("/list")
    public TableDataInfo list(ItProblemTrackingRecord itProblemTrackingRecord)
    {
        startPage();
        List<ItProblemTrackingRecord> list = itProblemTrackingRecordService.selectItProblemTrackingRecordList(itProblemTrackingRecord);
        return getDataTable(list);
    }

    /**
     * 导出跟踪记录列表
     */
    @RequiresPermissions("eduadmin:problem:export")
    @Log(title = "跟踪记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItProblemTrackingRecord itProblemTrackingRecord)
    {
        List<ItProblemTrackingRecord> list = itProblemTrackingRecordService.selectItProblemTrackingRecordList(itProblemTrackingRecord);
        ExcelUtil<ItProblemTrackingRecord> util = new ExcelUtil<ItProblemTrackingRecord>(ItProblemTrackingRecord.class);
        util.exportExcel(response, list, "跟踪记录数据");
    }

    /**
     * 获取跟踪记录详细信息
     */
    @RequiresPermissions("eduadmin:problem:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(itProblemTrackingRecordService.selectItProblemTrackingRecordById(id));
    }

    /**
     * 新增跟踪记录
     */
    @RequiresPermissions("eduadmin:problem:add")
    @Log(title = "跟踪记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItProblemTrackingRecord itProblemTrackingRecord)
    {
        return toAjax(itProblemTrackingRecordService.insertItProblemTrackingRecord(itProblemTrackingRecord));
    }

    @RequiresPermissions("eduadmin:problem:add")
    @Log(title = "跟踪记录", businessType = BusinessType.INSERT)
    @PutMapping("/addFollow")
    public AjaxResult addFollow(@RequestBody ItProblemTrackingRecord itProblemTrackingRecord)
    {

        itProblemTrackingRecordService.insertItProblemTrackingRecord(itProblemTrackingRecord);
        return toAjax(itStudentesService.deductPoints(itProblemTrackingRecord.getStudentId(),itProblemTrackingRecord.getDeductPoints()));
    }

    /**
     * 修改跟踪记录
     */
    @RequiresPermissions("eduadmin:problem:edit")
    @Log(title = "跟踪记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItProblemTrackingRecord itProblemTrackingRecord)
    {
        return toAjax(itProblemTrackingRecordService.updateItProblemTrackingRecord(itProblemTrackingRecord));
    }

    /**
     * 删除跟踪记录
     */
    @RequiresPermissions("eduadmin:problem:remove")
    @Log(title = "跟踪记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itProblemTrackingRecordService.deleteItProblemTrackingRecordByIds(ids));
    }

    /**
     * 根据学生id查询跟踪记录
     */
    @RequiresPermissions("eduadmin:problem:query")
    @GetMapping(value = "/getByStudentId/{studentId}")
    public AjaxResult getByStudentId(@PathVariable("studentId") Long studentId)
    {
        return success(itProblemTrackingRecordService.selectByStudentId(studentId));
    }
}
